import request from '@/utils/request'
import qs from 'qs'
import Vue from 'vue'
import {
  VXETable
} from 'vxe-table'
export async function get_status(data) {
  let res = await request({
    url: '/orgConfig/sysStatus/cache',
    method: 'post',
  })
  let dict_status = {}
  res.data.forEach(item=>{
    dict_status[item.statusId] = item.name
  })
  return dict_status
}

export async function get_role(data) {
  let res = await request({
    url: '/orgConfig/allOrgRole',
    method: 'post',
  })
  let dict_role = {}
  res.data.forEach(item=>{
    dict_role[item.roleId] = item.name
  })
  return dict_role
}

export async function get_sport(data) {
  let res = await request({
    url: '/data/sport/json/cache',
    method: 'post',
  })
  let dict_sport = {}
  res.data.forEach(item=>{
    dict_sport[item.sportId] = item.name
  })
  return dict_sport
}

export async function get_sport_all(data) {
  let res = await request({
    url: '/meta/sport/json/all',
    method: 'post',
  })
  if(data){
    return res.data
  }else{
    let dict_spor_all = {}
    res.data.forEach(item=>{
      dict_spor_all[item.sportId] = item.name
    })
    return dict_spor_all
  }
}

export async function coachByOrgIgnoreRole(data) {
  let res = await request({
    url: '/meta/coach/coachByOrgIgnoreRole',
    method: 'post',
  })
  let dict_coach = {}
  res.data.forEach(item=>{
    dict_coach[item.coachId] = item.name
  })
  return dict_coach
}

export async function ignoreRolePlayer(data) {
  let res = await request({
    url: '/meta/player/json/ignoreRolePlayer',
    method: 'post',
  })
  let dict_player = {}
  res.data.forEach(item=>{
    dict_player[item.playerId] = item.name
  })
  return dict_player
}

export async function employee_type(data) {
  let res = await request({
    url: '/data/employee_type/json/cache',
    method: 'post',
  })
  let dict_emp_type = {}
  res.data.forEach(item=>{
    dict_emp_type[item.empTypeId] = item.name
  })
  return dict_emp_type
}

export async function profession_type(data) {
  let res = await request({
    url: '/data/profession_type/json/cache',
    method: 'post',
  })
  let dict_profession_type = {}
  res.data.forEach(item=>{
    dict_profession_type[item.professionTypeId] = item.name
  })
  return dict_profession_type
}

export async function employee_status(data) {
  let res = await request({
    url: '/data/employee_status/json/cache',
    method: 'post',
  })
  let dict_employee_status = {}
  res.data.forEach(item=>{
    dict_employee_status[item.empStatusId] = item.name
  })
  return dict_employee_status
}

export async function sport_by_org(data) {
  let res = await request({
    url: '/meta/sport/json/all',
    method: 'post',
  })
  let dict_sport = {}
  res.data.forEach(item=>{
    dict_sport[item.sportId] = item.name
  })
  return dict_sport
}

export async function sport_item(data) {
  let res = await request({
    url: '/data/sport_item/json/all',
    method: 'post',
  })
  let dict_sport_item = {}
  res.data.forEach(item=>{
    dict_sport_item[item.sportItemId] = item.name
  })
  return dict_sport_item
}
export async function currentRolePlayer(data) {
  let res = await request({
    url: '/meta/player/json/currentRolePlayer',
    method: 'post',
  })
  if(data){
    return res.data
  }else{
    let dict_player = {}
    res.data.forEach(item=>{
      dict_player[item.playerId] = item.name
    })
    return dict_player
  }
}

export async function coach_type(data) {
  let res = await request({
    url: '/data/coach_type/json/cache',
    method: 'post',
  })
  let dict_coach_type = {}
  res.data.forEach(item=>{
    dict_coach_type[item.coachTypeId] = item.name
  })
  return dict_coach_type
}

export async function political_type(data) {
  let res = await request({
    url: '/data/political_type/json/cache',
    method: 'post',
  })
  let dict_political_type = {}
  res.data.forEach(item=>{
    dict_political_type[item.politicalId] = item.name
  })
  return dict_political_type
}

export async function selectDivisionPR(data) {
  let res = await request({
    url: '/person/division/selectDivisionPR',
    method: 'post',
  })
  let dict_divisionIdPR = {}
  res.data.forEach(item=>{
    dict_divisionIdPR[item.divId] = item.name
  })
  return dict_divisionIdPR
}

export async function selectDivisionCY(data) {
  let res = await request({
    url: '/person/division/selectDivisionCY',
    method: 'post',
  })
  let dict_divisionIdCY = {}
  res.data.forEach(item=>{
    dict_divisionIdCY[item.divId] = item.name
  })
  return dict_divisionIdCY
}

export async function selectDivisionCO(data) {
  let res = await request({
    url: '/person/division/selectDivisionCO',
    method: 'post',
  })
  let dict_division = {}
  res.data.forEach(item=>{
    dict_division[item.divId] = item.name
  })
  return dict_division
}

export async function coach_by_org(data) {
  let res = await request({
    url: '/meta/coach/coach_by_org',
    method: 'post',
  })
  let dict_coach = {}
  res.data.forEach(item=>{
    dict_coach[item.coachId] = item.name
  })
  return dict_coach
}

export async function getPosition(data) {
  let res = await request({
    url: '/data/position/json/cache',
    method: 'post',
  })
  let dict_position = {}
  res.data.forEach(item=>{
    dict_position[item.positionId] = item.name
  })
  return dict_position
}

export async function getWage_level(data) {
  let res = await request({
    url: '/data/wage_level/json/cache',
    method: 'post',
  })
  let dict_wage_level = {}
  res.data.forEach(item=>{
    dict_wage_level[item.wageLevelId] = item.name
  })
  return dict_wage_level
}

export async function getAppellation(data) {
  let res = await request({
    url: '/data/appellation/json/cache',
    method: 'post',
  })
  let dict_appellation = {}
  res.data.forEach(item=>{
    dict_appellation[item.appellationId] = item.name
  })
  return dict_appellation
}

export async function getLanguageLevel(data) {
  let res = await request({
    url: '/data/language_level/json/cache',
    method: 'post',
  })
  let dict_languageLevel = {}
  res.data.forEach(item=>{
    dict_languageLevel[item.langLevelId] = item.name
  })
  return dict_languageLevel
}

export async function getPersonByOrgEmp(data) {
  let res = await request({
    url: '/person/getPersonByOrgEmp',
    method: 'post',
  })
  let dict_pid = {}
  res.data.forEach(item=>{
    dict_pid[item.pid] = item.name
  })
  return dict_pid
}

export async function pId2sportIds4emp1(data) {
  let res = await request({
    url: '/dict/pId2sportIds4emp1',
    method: 'post',
  })
  let dict_pid_sport = {}
  res.data.forEach(item=>{
    dict_pid_sport[item.pId] = item.sportIdStr
  })
  return dict_pid_sport
}

export async function genEmpType(data) {
  let res = await request({
    url: '/meta/employee/genEmpType',
    method: 'post',
  })
  if(data){
    return res
  }else{
    let dict_pid_empTypeId = {}
    res.data.forEach(item=>{
      dict_pid_empTypeId[item.pid] = item.empTypeId
    })
    return dict_pid_empTypeId
  }

}

export async function userId2EmpName(data) {
  let res = await request({
    url: '/user/userId2EmpName',
    method: 'post',
  })
  let dict_userId2empName = {}
  res.data.forEach(item=>{
    dict_userId2empName[item.userId] = item.empName
  })
  return dict_userId2empName
}

export async function empId2sportInfo(sport) {
  let res = await request({
    url: '/dict/empId2sportInfo',
    method: 'post',
  })
  let dict_empid2sports = {}
  res.data.forEach(item=>{
    if(sport){
      dict_empid2sports[item.empId] = item.sportInfo
    }else{
      dict_empid2sports[item.empId] = item.empName
    }
  })
  return dict_empid2sports
}

export async function player_status(data) {
  let res = await request({
    url: '/data/player_status/json/cache',
    method: 'post',
  })
  let dict_playerStatus = {}
  res.data.forEach(item=>{
    dict_playerStatus[item.playerStatusId] = item.name
  })
  return dict_playerStatus
}

export async function focus_type(data) {
  let res = await request({
    url: '/data/focus_type/json/cache',
    method: 'post',
  })
  let dict_focus_type = {}
  res.data.forEach(item=>{
    dict_focus_type[item.focusTypeId] = item.name
  })
  return dict_focus_type
}

export async function all_org(data) {
  let res = await request({
    url: '/data/all_org/json/all',
    method: 'post',
  })
  let dict_allOrg = {}
  res.data.forEach(item=>{
    dict_allOrg[item.orgId] = item.name
  })
  return dict_allOrg
}

export async function toward(data) {
  let res = await request({
    url: '/data/toward/json/cache',
    method: 'post',
  })
  let dict_towar = {}
  res.data.forEach(item=>{
    dict_towar[item.towardId] = item.name
  })
  return dict_towar
}

export async function training_status(data) {
  let res = await request({
    url: '/data/training_status/json/cache',
    method: 'post',
  })
  let dict_training_status = {}
  res.data.forEach(item=>{
    dict_training_status[item.trainingStatusId] = item.name
  })
  return dict_training_status
}

export async function match_event(data) {
  let res = await request({
    url: '/match/match_event/json/cache',
    method: 'post',
  })
  let dict_match_event = {}
  res.data.forEach(item=>{
    dict_match_event[item.matchEventId] = item.name
  })
  return dict_match_event
}

export async function match_event_item(data) {
  let res = await request({
    url: '/match/match_event_item/json/all',
    method: 'post',
  })
  let dict_match_event_item = {}
  res.data.forEach(item=>{
    dict_match_event_item[item.matchEventItemId] = item.name
  })
  return dict_match_event_item
}

export async function getDelegation(data) {
  let res = await request({
    url: '/match/delegation/json/cache',
    method: 'post',
  })
  let dict_delegation = {}
  res.data.forEach(item=>{
    dict_delegation[item.delegationId] = item.name
  })
  return dict_delegation
}

export async function record_break(data) {
  let res = await request({
    url: '/match/record_break/json/cache',
    method: 'post',
  })
  let dict_recordBreak = {}
  res.data.forEach(item=>{
    dict_recordBreak[item.recordBreakId] = item.name
  })
  return dict_recordBreak
}

export async function match_level(data) {
  let res = await request({
    url: '/match/match_level/json/all',
    method: 'post',
  })
  let dict_matchLevel = {}
  res.data.forEach(item=>{
    dict_matchLevel[item.matchLevelId] = item.name
  })
  return dict_matchLevel
}

export async function match_group_type(data) {
  let res = await request({
    url: '/match/match_group_type/json/cache',
    method: 'post',
  })
  let dict_matchGroupType = {}
  res.data.forEach(item=>{
    dict_matchGroupType[item.matchGroupTypeId] = item.name
  })
  return dict_matchGroupType
}

export async function match_kind(data) {
  let res = await request({
    url: '/match/match_kind/json/all',
    method: 'post',
  })
  let dict_matchKin = {}
  res.data.forEach(item=>{
    dict_matchKin[item.matchKindId] = item.name
  })
  return dict_matchKin
}

export async function match_address(data) {
  let res = await request({
    url: '/match/match_address/json/cache',
    method: 'post',
  })
  let dict_matchAddress = {}
  res.data.forEach(item=>{
    dict_matchAddress[item.matchAddressId] = item.name
  })
  return dict_matchAddress
}

export async function pId2coachIds(data) {
  let res = await request({
    url: '/dict/pId2coachIds',
    method: 'post',
  })
  let dict_pid2coach = {}
  res.data.forEach(item=>{
    dict_pid2coach[item.pId] = item.coachIdStr
  })
  return dict_pid2coach
}

export async function availableCoach(data) {
  let res = await request({
    url: '/meta/coach/availableCoach',
    method: 'post',
  })
  let dict_coach = {}
  res.data.forEach(item=>{
    dict_coach[item.coachId] = item.name
  })
  return dict_coach
}

export async function pId2sportIds4player(data) {
  let res = await request({
    url: '/dict/pId2sportIds4player',
    method: 'post',
  })
  let dict_pid2sportIds = {}
  res.data.forEach(item=>{
    dict_pid2sportIds[item.pId] = item.sportIdStr
  })
  return dict_pid2sportIds
}

export async function grade_type(data) {
  let res = await request({
    url: '/data/grade_type/json/cache',
    method: 'post',
  })
  let dict_grade_type = {}
  res.data.forEach(item=>{
    dict_grade_type[item.gradeId] = item.name
  })
  return dict_grade_type
}

export async function player2gradeId(data) {
  let res = await request({
    url: '/meta/player/json/currentRolePlayer',
    method: 'post',
  })
  let dict_player2gradeId = {}
  res.data.forEach(item=>{
    dict_player2gradeId[item.playerId] = item.gradeId
  })
  return dict_player2gradeId
}

export async function pcm4coach(data) {
  let res = await request({
    url: '/meta/player_coach_map/pcm4coach',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_coach = {}
  res.data.forEach(item=>{
    dict_coach[item.coachId] = item.name
  })
  return dict_coach
}

export async function pcm4dict(data) {
  let res = await request({
    url: '/meta/player_coach_map/pcm4dict',
    method: 'post',
  })
  let dict = {
    dict_playerId2coachIds:res.data.player2CoachIdStr,
    dict_playerId2sportIds:res.data.player2SportIdStr
  }
  return dict
}

export async function pcm4player(data) {
  let res = await request({
    url: '/meta/player_coach_map/pcm4player',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_player = {}
  res.data.forEach(item=>{
    dict_player[item.playerId] = item.name
  })
  return dict_player
}

export async function dormAll(data) {
  let res = await request({
    url: '/dorm/json/all',
    method: 'post',
  })
  let dict_dorm = {}
  res.data.forEach(item=>{
    dict_dorm[item.dormId] = item.name
  })
  return dict_dorm
}

export async function currentRoleEmployee(data) {
  let res = await request({
    url: '/meta/employee/json/currentRoleEmployee',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_emp = {}
  res.data.forEach(item=>{
    dict_emp[item.empId] = item.name
  })
  return dict_emp
}

export async function getAllEmp(data) {
  let res = await request({
    url: '/meta/employee/getAllEmp',
    method: 'post',
  })
  let dict_emp = {}
  res.data.forEach(item=>{
    dict_emp[item.empId] = item.name
  })
  return dict_emp
}

export async function dorm_standard(data) {
  let res = await request({
    url: '/data/dorm_standard/json/cache',
    method: 'post',
  })
  let dict_dormStandard = {}
  res.data.forEach(item=>{
    dict_dormStandard[item.dormStandardId] = item.name
  })
  return dict_dormStandard
}

export async function player_process_result(data) {
  let res = await request({
    url: '/data/player_process_result/json/all',
    method: 'post',
  })
  let dict_result = {}
  res.data.forEach(item=>{
    dict_result[item.resultId] = item.name
  })
  return dict_result
}

export async function plan_doc_available(data) {
  let res = await request({
    url: '/plan/plan_doc/available',
    method: 'post',
  })
  let dict_available = {}
  res.data.forEach(item=>{
    dict_available[item.docClassId] = item.name
  })
  return dict_available
}

export async function pcm4sport(data) {
  let res = await request({
    url: '/meta/player_coach_map/pcm4sport',
    method: 'post',
  })
  let dict_sport = {}
  res.data.forEach(item=>{
    dict_sport[item.sportId] = item.name
  })
  return dict_sport
}

export async function sport_item_cache(data) {
  let res = await request({
    url: '/data/sport_item/json/cache',
    method: 'post',
  })
  let dict_sport_item = {}
  res.data.forEach(item=>{
    dict_sport_item[item.sportItemId] = item.name
  })
  return dict_sport_item
}

export async function template_allByUsageId(data) {
  let res = await request({
    url: '/meta/template/json/allByUsageId',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_template = {}
  res.data.forEach(item=>{
    dict_template[item.templateId] = item.name
  })
  return dict_template
}

export async function meta_sport_item_cache(data) {
  let res = await request({
    url: '/meta/sport_item/json/cache/sportId',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_sport_item = {}
  res.data.forEach(item=>{
    dict_sport_item[item.sportItemId] = item.name
  })
  return dict_sport_item
}

export async function get_player(data) {
  let res = await request({
    url: '/meta/player_coach_map/get_player',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_player = {}
  res.data.forEach(item=>{
    dict_player[item.playerId] = item.name
  })
  return dict_player
}

export async function meta_all(data) {
  let res = await request({
    url: '/meta/json/all',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_meta = {}
  res.data.forEach(item=>{
    dict_meta[item.metaId] = item.name
  })
  return dict_meta
}

export async function meta_cache(data) {
  let res = await request({
    url: '/data/meta/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_meta = {}
  res.data.forEach(item=>{
    dict_meta[item.metaId] = item.name
  })
  return dict_meta
}

export async function coach_by_sport(data) {
  let res = await request({
    url: '/meta/coach/coach_by_sport',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_coach = {}
  res.data.forEach(item=>{
    dict_coach[item.coachId] = item.name
  })
  return dict_coach
}

export async function grade_class(data) {
  let res = await request({
    url: '/grade_class/forDict',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_grade_class = {}
  res.data.forEach(item=>{
    dict_grade_class[item.schoolGradeClassId] = item.name
  })
  return dict_grade_class
}

export async function doc_class_item_type(data) {
  let res = await request({
    url: '/plan/doc_class_item_type/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_doc_class_item_type = {}
  res.data.forEach(item=>{
    dict_doc_class_item_type[item.docClassItemTypeId] = item.name
  })
  return dict_doc_class_item_type
}

export async function docDataId2departmentName(data) {
  let res = await request({
    url: '/plan/plan_doc/docDataId2departmentName',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_docDataId2departmentName = {}
  res.data.forEach(item=>{
    dict_docDataId2departmentName[item.docDataId] = item.name
  })
  return dict_docDataId2departmentName
}

export async function regulation_department(data) {
  let res = await request({
    url: '/data/regulation_department/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict_department = {}
  res.data.forEach(item=>{
    dict_department[item.regulationDepartmentId] = item.name
  })
  return dict_department
}

export async function ground_type(data) {
  let res = await request({
    url: '/data/ground_type/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.groundTypeId] = item.name
  })
  return dict
}

export async function ground_env(data) {
  let res = await request({
    url: '/data/ground_env/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.groundEnvId] = item.name
  })
  return dict
}

export async function ground_access_type(data) {
  let res = await request({
    url: '/data/ground_access_type/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.groundAccessTypeId] = item.name
  })
  return dict
}

export async function ground_open_type(data) {
  let res = await request({
    url: '/data/ground_open_type/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.groundOpenTypeId] = item.name
  })
  return dict
}

export async function ground_status(data) {
  let res = await request({
    url: '/data/ground_status/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.groundStatusId] = item.name
  })
  return dict
}

export async function sport_item_by_sportId(data) {
  let res = await request({
    url: 'meta/sport_item/json/all/'+data,
    method: 'post',
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.sportItemId] = item.name
  })
  return dict
}

export async function instrument_status(data) {
  let res = await request({
    url: '/data/instrument_status/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.statusId] = item.name
  })
  return dict
}

export async function science_instrument_type(data) {
  let res = await request({
    url: '/data/science_instrument_type/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.typeId] = item.name
  })
  return dict
}

export async function gun_type(data) {
  let res = await request({
    url: '/asset/gun_type/json/all',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.typeId] = item.name
  })
  return dict
}

export async function json4OrgGunLicense(data) {
  let res = await request({
    url: '/meta/organization/json4OrgGunLicense',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.orgId] = item.name
  })
  return dict
}

export async function gun_brand(data) {
  let res = await request({
    url: '/asset/gun_brand/json/all',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.brandId] = item.name
  })
  return dict
}

export async function gun_store(data) {
  let res = await request({
    url: '/asset/gun_store/json/all',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.storeId] = item.name
  })
  return dict
}

export async function available4planStatistics(data) {
  let res = await request({
    url: '/plan/plan_doc/available4planStatistics',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.docClassId] = item.name
  })
  return dict
}

export async function all4planStatistics(data) {
  let res = await request({
    url: '/plan/plan_doc/json/all4planStatistics',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  for (var i = 0; i < res.data.length; i++) {
  let docDataId = res.data[i][0];
  let docClassId = res.data[i][1];
  let openDate = res.data[i][2]+"";
  let closeDate = res.data[i][3]+"";
  if (docClassId == 34) dict[docDataId] = Vue.prototype.$moment(openDate).format("YYYY-MM-DD");
  else dict[docDataId] = Vue.prototype.$moment(openDate).format("YYYY-MM-DD") + '到' + Vue.prototype.$moment(closeDate).format("YYYY-MM-DD");
  }
  return dict
}

export async function by_sportId(data) {
  let res = await request({
    url: '/meta/sport_item/by_sportId',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.sportItemId] = item.name
  })
  return dict
}

export async function pcm4emp(data) {
  let res = await request({
    url: '/meta/player_coach_map/pcm4emp',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.empId] = item.name
  })
  return dict
}

export async function sport_ignoreOrg(data) {
  let res = await request({
    url: '/meta/sport/json/ignoreOrg',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.sportId] = item.name
  })
  return dict
}

export async function meta_package(data) {
  let res = await request({
    url: '/data/meta_package/json/cache',
    method: 'post',
    data: qs.stringify(data)
  })
  let dict= {}
  res.data.forEach(item=>{
    dict[item.packageId] = item.shortName
  })
  return dict
}
